﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucControlFecha.ascx.cs" Inherits="Controles.Principal.ucControlFecha" %>
<%@ Register TagPrefix="rjs" Namespace="RJS.Web.WebControl" Assembly="RJS.Web.WebControl.PopCalendar" %>
<LINK href="PopCalendar/CSS/MiEstilo.css" type="text/css" rel="stylesheet">
<script language="javascript" src="PopCalendar/PopCalendar.js" type="text/javascript"></script>
<script language="javascript" src="Scripts/JScript.js" type="text/javascript"></script>
<script language="javascript" src="PopCalendar/PopCalendarFunctions.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
    function valFecha(oTxt) {
        var bOk = true;
        if (oTxt.value != "__/__/____") {
            bOk = bOk && (valDia(oTxt));
            bOk = bOk && (valMes(oTxt));
            bOk = bOk && (valAno(oTxt));


            bOk = bOk && (valSep(oTxt));

            if (!bOk) {
                alert("Fecha inválida");
                oTxt.value = "";
                oTxt.focus();
            }
        }
    }
    function valDia(oTxt) {
        var bOk = false;
        var nDia = parseInt(oTxt.value.substr(0, 2), 10);
        bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
        return bOk;
    }

    function valMes(oTxt) {
        var bOk = false;
        var nMes = parseInt(oTxt.value.substr(3, 2), 10);
        bOk = bOk || ((nMes >= 1) && (nMes <= 12));
        return bOk;
    }

    function valAno(oTxt) {
        var bOk = true;
        var nAno = oTxt.value.substr(6);
        bOk = bOk && (nAno.length == 4);
        if (bOk) {
            for (var i = 0; i < nAno.length; i++) {
                bOk = bOk && esDigito(nAno.charAt(i));
            }
        }
        return bOk;
    }
    function valSep(oTxt) {
        var bOk = false;
        bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
        return bOk;
    }
    function esDigito(sChr) {
        var sCod = sChr.charCodeAt(0);
        return ((sCod > 47) && (sCod < 58));
    }
    function finMes(oTxt) {
        var nMes = parseInt(oTxt.value.substr(3, 2), 10);
        var nRes = 0;
        switch (nMes) {
            case 1: nRes = 31; break;
            case 2:
                if (parseInt(oTxt.value.substr(6)) % 4 == 0) {
                    nRes = 29;
                }
                else {
                    nRes = 28;
                }

                break;
            case 3: nRes = 31; break;
            case 4: nRes = 30; break;
            case 5: nRes = 31; break;
            case 6: nRes = 30; break;
            case 7: nRes = 31; break;
            case 8: nRes = 31; break;
            case 9: nRes = 30; break;
            case 10: nRes = 31; break;
            case 11: nRes = 30; break;
            case 12: nRes = 31; break;
        }
        return nRes;
    }
</script>

<asp:TextBox id="txtFecha" runat="server" Width="95px" CssClass="textotabulado"  BorderWidth="1px"
	BorderColor="#999999" OnBlur="javascript:valFecha(this);"></asp:TextBox>

<rjs:PopCalendar CssClass="MiEstilo" id="btnFecha" runat="server" Control="txtFecha" ShowWeekend="True"
	ShowToday="False" ShowBlankFieldText="True" Separator="/" ShowErrorMessage="False"></rjs:PopCalendar><INPUT id="hidCFSessionHerramienta" style="WIDTH: 8px; HEIGHT: 22px" type="hidden" size="1"
	name="hidMPSessionHerramienta" runat="server"> <INPUT id="hidFechaAutoPostBack" style="WIDTH: 8px; HEIGHT: 22px" type="hidden" size="1"
	name="hidFechaAutoPostBack" value="0" runat="server">
